const birdDom = document.querySelector(".bird");
const birdStyle = getComputedStyle(birdDom);
const birdWidth = parseFloat(birdStyle.width);
const birdHeight = parseFloat(birdStyle.height);
const birdLeft = parseFloat(birdStyle.left);
const birdTop = parseFloat(birdStyle.top);
const gameDom = document.querySelector(".wrapper");
const maxTop = gameDom.clientHeight;

class Bird extends person{
    constructor(){
        super(birdWidth,birdHeight,birdLeft,birdTop,0,0,birdDom);
        this.g = 1500;
        this.maxY = maxTop - birdHeight;
        this.swingStatus = 1;
        this.timer = null;
        this.render();

    }

    move(tim){
        super.move(tim);
        this.ySpeed += this.g * tim;
    }

    onMove(){
        if(this.top < 0){
            this.top = 0;
        }else if(this.top >= this.maxY){
            this.top = this.maxY;
        }
    }

    jump(){
        this.ySpeed = -400;
    }

    startFly(){
        if(this.timer){
            return;
        }
        this.timer = setInterval(() =>{
            this.swingStatus ++;
            if(this.swingStatus == 4){
                this.swingStatus = 1;
            }
            this.render();
        },200)
    }

    render(){
        super.render();
        this.dom.className = `bird swing${this.swingStatus}`;
    }
    stopFly(){
        clearInterval(this.timer);
        this.timer = null;
    }
}

